home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ftp / RCS / domacro.c,v < prev    next >
Encoding:
Text File  |  1990-10-27  |  3.9 KB  |  195 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.10.27.13.48.38;  author shirriff;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.10.27.13.45.19;  author shirriff;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @New revision.
  27. @
  28. text
  29. @/*
  30.  * Copyright (c) 1985 Regents of the University of California.
  31.  * All rights reserved.
  32.  *
  33.  * Redistribution and use in source and binary forms are permitted
  34.  * provided that the above copyright notice and this paragraph are
  35.  * duplicated in all such forms and that any documentation,
  36.  * advertising materials, and other materials related to such
  37.  * distribution and use acknowledge that the software was developed
  38.  * by the University of California, Berkeley.  The name of the
  39.  * University may not be used to endorse or promote products derived
  40.  * from this software without specific prior written permission.
  41.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  42.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  43.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  44.  */
  45.  
  46. #ifndef lint
  47. static char sccsid[] = "@@(#)domacro.c    1.6 (Berkeley) 2/28/89";
  48. #endif /* not lint */
  49.  
  50. #include "ftp_var.h"
  51.  
  52. #include <signal.h>
  53. #include <stdio.h>
  54. #include <errno.h>
  55. #include <ctype.h>
  56. #include <sys/ttychars.h>
  57.  
  58. domacro(argc, argv)
  59.     int argc;
  60.     char *argv[];
  61. {
  62.     register int i, j;
  63.     register char *cp1, *cp2;
  64.     int count = 2, loopflg = 0;
  65.     char line2[200];
  66.     extern char **glob(), *globerr;
  67.     struct cmd *getcmd(), *c;
  68.     extern struct cmd cmdtab[];
  69.  
  70.     if (argc < 2) {
  71.         (void) strcat(line, " ");
  72.         printf("(macro name) ");
  73.         (void) gets(&line[strlen(line)]);
  74.         makeargv();
  75.         argc = margc;
  76.         argv = margv;
  77.     }
  78.     if (argc < 2) {
  79.         printf("Usage: %s macro_name.\n", argv[0]);
  80.         code = -1;
  81.         return;
  82.     }
  83.     for (i = 0; i < macnum; ++i) {
  84.         if (!strncmp(argv[1], macros[i].mac_name, 9)) {
  85.             break;
  86.         }
  87.     }
  88.     if (i == macnum) {
  89.         printf("'%s' macro not found.\n", argv[1]);
  90.         code = -1;
  91.         return;
  92.     }
  93.     (void) strcpy(line2, line);
  94. TOP:
  95.     cp1 = macros[i].mac_start;
  96.     while (cp1 != macros[i].mac_end) {
  97.         while (isspace(*cp1)) {
  98.             cp1++;
  99.         }
  100.         cp2 = line;
  101.         while (*cp1 != '\0') {
  102.               switch(*cp1) {
  103.                    case '\\':
  104.                  *cp2++ = *++cp1;
  105.                  break;
  106.                 case '$':
  107.                  if (isdigit(*(cp1+1))) {
  108.                     j = 0;
  109.                     while (isdigit(*++cp1)) {
  110.                       j = 10*j +  *cp1 - '0';
  111.                     }
  112.                     cp1--;
  113.                     if (argc - 2 >= j) {
  114.                     (void) strcpy(cp2, argv[j+1]);
  115.                     cp2 += strlen(argv[j+1]);
  116.                     }
  117.                     break;
  118.                  }
  119.                  if (*(cp1+1) == 'i') {
  120.                     loopflg = 1;
  121.                     cp1++;
  122.                     if (count < argc) {
  123.                        (void) strcpy(cp2, argv[count]);
  124.                        cp2 += strlen(argv[count]);
  125.                     }
  126.                     break;
  127.                 }
  128.                 /* intentional drop through */
  129.                 default:
  130.                 *cp2++ = *cp1;
  131.                 break;
  132.               }
  133.               if (*cp1 != '\0') {
  134.              cp1++;
  135.               }
  136.         }
  137.         *cp2 = '\0';
  138.         makeargv();
  139.         c = getcmd(margv[0]);
  140.         if (c == (struct cmd *)-1) {
  141.             printf("?Ambiguous command\n");
  142.             code = -1;
  143.         }
  144.         else if (c == 0) {
  145.             printf("?Invalid command\n");
  146.             code = -1;
  147.         }
  148.         else if (c->c_conn && !connected) {
  149.             printf("Not connected.\n");
  150.             code = -1;
  151.         }
  152.         else {
  153.             if (verbose) {
  154.                 printf("%s\n",line);
  155.             }
  156.             (*c->c_handler)(margc, margv);
  157.             if (bell && c->c_bell) {
  158.                 (void) putchar('\007');
  159.             }
  160.             (void) strcpy(line, line2);
  161.             makeargv();
  162.             argc = margc;
  163.             argv = margv;
  164.         }
  165.         if (cp1 != macros[i].mac_end) {
  166.             cp1++;
  167.         }
  168.     }
  169.     if (loopflg && ++count < argc) {
  170.         goto TOP;
  171.     }
  172. }
  173. @
  174.  
  175.  
  176. 1.1
  177. log
  178. @Initial revision
  179. @
  180. text
  181. @d6 10
  182. a15 5
  183.  * provided that this notice is preserved and that due credit is given
  184.  * to the University of California at Berkeley. The name of the University
  185.  * may not be used to endorse or promote products derived from this
  186.  * software without specific prior written permission. This software
  187.  * is provided ``as is'' without express or implied warranty.
  188. d19 1
  189. a19 1
  190. static char sccsid[] = "@@(#)domacro.c    1.4 (Berkeley) 3/14/88";
  191. d130 1
  192. a130 1
  193.                 (void) putchar(CTRL('g'));
  194. @
  195.